<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //函数（方法）  执行特定任务    功能输入输出
        //用户输入两个数，比如依次输入a和b(前提a<b),计算a到b的累加和

        //定义两个变量接收用户输入的数字
        let num1 = +prompt('请输入你需要进行累加和的数字(前提a<b)')
        let num2 = +prompt('请输入你需要进行累加和的数字(前提a<b)')
        if (num1 <=num2) {
            function sumCount(num1, num2) {
          
                let sum = 0
                for (let i = num1; i <= num2; i++) {
                    sum += i
                }
                console.log(sum)
                return sum
            }
            let re = sumCount(num1, num2)
            document.write(`${num1}和${num2}的累加和为${re}`)

          
        } else if (num1 > num2) {
            alert('输入的数字不合法请重新输入')
        }




    </script>

</body>

</html>